#include <cstdio>
using namespace std;
const int N = 11;
int n, a[N], visit[N];
void output () {
	for (int i = 1; i <= n; i++) {
		printf ("%5d", a[i]);
	}
	printf ("\n");
}
void dfs (int k) {
	if (k == n) {
		output();
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (!visit[i]) {
			a[k + 1] = i;
			visit[i] = 1;
			dfs (k + 1);
			visit[i] = 0;
		}
	}
}
int main() {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		a[i] = i;
	}
	dfs(0);
	return 0;
}